
/**
 *
 */

class TMSBridge {
  wxc = wx
  component = false
  static navPageMap = new Map()

  constructor(setting = {}) {
    const { component } = setting;
    this.component = !!component;
  }

  bind(wxc = wx) {
    this.wxc = wxc;
    return this;
  }

  scope(fpsc) {
    return this.component && !fpsc ? wx : this.wxc;
  }

  navigateToPlugin(setting) {
    const { appId, url, fpsc, complete = (err) => console.log(err) } = setting;
    const page = TMSBridge.navPageMap.get(appId);
    this.scope(fpsc).navigateTo({
      complete,
      url: `${page}${/\?/.test(page) ? '&' : '?'}path=${encodeURIComponent(url)}`,
    });
  }
}

// 设置目标插件所在的位置
TMSBridge.navPageMap.set('wx381a393cd6daf202', '/submain/pages/reurl/reurl');

module.exports = { TMSBridge: new TMSBridge({ component: true }) };